﻿<template>
  <a-modal
    title="编辑门诊订单"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="客户ID " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入客户ID " v-decorator="['customerId']" />
        </a-form-item>
        <a-form-item label="会员卡号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入会员卡号 " v-decorator="['icCode']" />
        </a-form-item>
        <a-form-item label="原价 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入原价 " v-decorator="['originalAmount']" />
        </a-form-item>
        <a-form-item label="支付金额 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入支付金额 " v-decorator="['payAmount']" />
        </a-form-item>
        <a-form-item label="订单状态 0 已生成 1支付中 2 已结算 3 取消 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入订单状态 0 已生成 1支付中 2 已结算 3 取消 " v-decorator="['status']" />
        </a-form-item>
        <a-form-item label="一口价 特殊优惠的时候修改改一口 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入一口价 特殊优惠的时候修改改一口 " v-decorator="['fixedAmount']" />
        </a-form-item>
        <a-form-item label="备注 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入备注 " v-decorator="['remark']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field01']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field02']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field03']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field04']" />
        </a-form-item>
        <a-form-item label="扩展字段 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入扩展字段 " v-decorator="['field05']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['iD']" /></a-form-item>
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-decorator="['creatceDate']" @change="onChangecreatceDate"/>
        </a-form-item>
        <a-form-item label="创建者Id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者Id" v-decorator="['createUserId']" />
        </a-form-item>
        <a-form-item label="创建者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者名称" v-decorator="['createUserName']" />
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-decorator="['modifyDate']" @change="onChangemodifyDate"/>
        </a-form-item>
        <a-form-item label="修改者Id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者Id" v-decorator="['modifyUserId']" />
        </a-form-item>
        <a-form-item label="修改者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者名称" v-decorator="['modifyUserName']" />
        </a-form-item>
        <a-form-item label="删除时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择删除时间" v-decorator="['deleteDate']" @change="onChangedeleteDate"/>
        </a-form-item>
        <a-form-item label="删除者ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入删除者ID" v-decorator="['deleteUserId']" />
        </a-form-item>
        <a-form-item label="删除者姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入删除者姓名" v-decorator="['deleteUserName']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import moment from 'moment'
  import {
    OutpOrderEdit
  } from '@/api/modular/main/OutpOrderManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        creatceDateDateString: '',
        modifyDateDateString: '',
        deleteDateDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      moment,
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              iD: record.iD,
              customerId: record.customerId,
              icCode: record.icCode,
              originalAmount: record.originalAmount,
              payAmount: record.payAmount,
              status: record.status,
              fixedAmount: record.fixedAmount,
              remark: record.remark,
              field01: record.field01,
              field02: record.field02,
              field03: record.field03,
              field04: record.field04,
              field05: record.field05,
              createUserId: record.createUserId,
              createUserName: record.createUserName,
              modifyUserId: record.modifyUserId,
              modifyUserName: record.modifyUserName,
              deleteUserId: record.deleteUserId,
              deleteUserName: record.deleteUserName
            }
          )
        }, 100)
        this.form.getFieldDecorator('creatceDate', { initialValue: moment(record.creatceDate, 'YYYY-MM-DD') })
        this.creatceDateDateString = moment(record.creatceDate).format('YYYY-MM-DD')
        this.form.getFieldDecorator('modifyDate', { initialValue: moment(record.modifyDate, 'YYYY-MM-DD') })
        this.modifyDateDateString = moment(record.modifyDate).format('YYYY-MM-DD')
        this.form.getFieldDecorator('deleteDate', { initialValue: moment(record.deleteDate, 'YYYY-MM-DD') })
        this.deleteDateDateString = moment(record.deleteDate).format('YYYY-MM-DD')
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.creatceDate = this.creatceDateDateString
            values.modifyDate = this.modifyDateDateString
            values.deleteDate = this.deleteDateDateString
            OutpOrderEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangecreatceDate(date, dateString) {
        this.creatceDateDateString = dateString
      },
      onChangemodifyDate(date, dateString) {
        this.modifyDateDateString = dateString
      },
      onChangedeleteDate(date, dateString) {
        this.deleteDateDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
